--- 'Monoid' instances for bounded and ordered values, using 'min' and 'max'
module frege.data.wrapper.Ord where

import Data.Monoid

  
newtype Min a = Min { unwrap :: a }
derive Show (Min a)
derive Eq   (Min a)
derive Ord  (Min a)

getMin = Min.unwrap

instance (Ord a, Bounded a) => Monoid (Min a) where
  mempty = Min maxBound
instance Ord a => Semigroup (Min a) where
  Min a `mappend` Min b = Min (a `min` b)
    
  
newtype Max a = Max { unwrap :: a }
derive Show (Max a)
derive Eq   (Max a)
derive Ord  (Max a)

getMax = Max.unwrap

instance (Ord a, Bounded a) => Monoid (Max a) where
  mempty = Max minBound
instance Ord a => Semigroup (Max a) where
  Max a `mappend` Max b = Max (a `max` b)
